window.onload=function() {
    var userId = sessionStorage.getItem('userId');
    console.log(userId);
    var brand="";//运营专员
    var provider="";//运营商Id
    var machines_name="";//机台名称Id
    var IP='https://up-bi.pec.com.cn';
    var modelSend = {
        "model": 'sku_board',
        "condition": {
            "year_month":''
        },
        "item": {"sale_amount": [1,2],
            "main_index": {"sale_amount": 1}//主指标
        }//数据指标
    };
    modelSend.condition.manage_name = 0;
    modelSend.condition.brand = "";//运营专员
    modelSend.condition.provider = "";//运营商Id
    modelSend.condition.machines_name="";//机台名称Id
    console.log(modelSend)
    $(".header a[href='#pageone']").click(function(){
        modelSend.condition.brand = "";//运营专员
        modelSend.condition.provider = "";//运营商Id
        modelSend.condition.machines_name="";//机台名称Id
        modelSend.condition.manage_name = "";
        modelSend.condition.manage_name = "";
        console.log(modelSend)
    });
    $.ajax({
        url: IP+'/data-center/recentBorad/getRecentBoardInfo?token='+userId,
        type: "POST",
        data:{"paramData":JSON.stringify(modelSend)},
        success: function(data) {
            console.log(data)
            var str='';
            for (var i=0;i<data.data.length;i++){
                str+='<li ><a id='+data.data[i].label+' href="#pageName" class="ui-btn ui-btn-icon-right ui-icon-carat-r">'+data.data[i].value+'</a></li>';
            }
            $(".list").html(str)
        }

    });
    $('.list').on('click','li>a',function(){
        brand.length=0;
        modelSend.condition.brand = "";
        brand=$(this).attr('id');
        modelSend.condition.brand = brand;
        modelSend.condition.provider = "";//运营商Id
        modelSend.condition.machines_name="";//机台名称Id
        modelSend.condition.manage_name = "";
        name();
    });
    function  name() {
        console.log(modelSend)
        $.ajax({
            url: IP + '/data-center/recentBorad/getRecentBoardInfo?token=' +userId,
            type: "POST",
            data: {"paramData": JSON.stringify(modelSend)},
            success: function (data) {
                console.log(data)
                var str='';
                for (var i=0;i<data.data.length;i++) {
                    str += '<li ><a id='+data.data[i].label+' href="#pageBoard" class="ui-btn ui-btn-icon-right ui-icon-carat-r">' + data.data[i].value + '</a></li>';
                }
                $(".name").html(str)
            }
        });
        $('.name').on('click','li>a',function(){
            provider.length=0;
            modelSend.condition.provider="";
            provider= $(this).attr('id');
            modelSend.condition.provider = provider;
            modelSend.condition.manage_name = "";
            modelSend.condition.brand = "";//运营专员
            modelSend.condition.machines_name="";//机台名称Id
            console.log(modelSend);
            board();
        });
    };
    function board() {
        $.ajax({
            url: IP + '/data-center/recentBorad/getRecentBoardInfo?token=' +userId,
            type: "POST",
            data: {"paramData": JSON.stringify(modelSend)},
            success: function (data) {
                console.log(data)
                var str='';
                for (var i=0;i<data.data.length;i++) {
                    str += '<li ><a id='+data.data[i].label+' href="#pagedetail" class="ui-btn ui-btn-icon-right ui-icon-carat-r">' + data.data[i].value + '</a></li>';
                }
                $(".board").html(str)
            }
        });
        $('.board').on('click','li>a',function(){
            machines_name.length=0;
            modelSend.condition.machines_name="";
            machines_name=$(this).attr('id');
            modelSend.condition.machines_name = machines_name;
            modelSend.condition.manage_name = "";
            modelSend.condition.brand = "";//运营专员
            modelSend.condition.provider = "";//运营商Id
            console.log(modelSend)
            detail();
        });
    };
    function detail(){
        $.ajax({
            url: IP + '/data-center/recentBorad/getRecentBoardInfo?token=' + userId,
            type: "POST",
            data: {"paramData": JSON.stringify(modelSend)},
            success: function (data) {
                $("#box").remove();
                console.log(data);
                var str="";
                for (var i=0;i<data.data.length;i++){
                    var stockout=data.data[i].stockout;
                    str+='<ul  class="con nav" id="box">' +
                        '<li>'+data.data[i].code+'</li>' +
                        '<li>'+data.data[i].vendor_name+'</li>' +
                        '<li>'+data.data[i].sum_oos+'</li>' +
                        '<li id="first" class="first">'+data.data[i].count_oos+'<a href="#" class="ui-btn ui-corner-all ui-icon-arrow-d ui-btn-icon-notext">图标</a></li>' +
                        '<li class="only" style="display: none;width: 100%;height:100%;padding: 0;"><div>' +
                        '<ul class="show" >' +
                        '<li>货道号</li>' +
                        '<li>商品编号</li>' +
                        '<li>商品名称</li>' +
                        '</ul>';
                    for(var m=0;m<stockout.length;m++){
                        var s=stockout[m].sku_code==null?"":stockout[m].sku_code;
                        var t=stockout[m].sku_name==null?"":stockout[m].sku_name;
                        str+='<ul class="show" >' +
                            '<li>'+stockout[m].oos_mark+'</li>' +
                            '<li>'+s+'</li>' +
                            '<li style="line-height: normal;word-wrap: break-word;word-break: normal;">'+t+'</li>' +
                            '</ul>';
                    }
                    str+='</div></li>'+
                        '</ul>';
                }


                $("#myTab").after(str);
/*
                $("#first").after(ul)
*/
                /*for (var m=0;m<$(".ui-content>ul.con>li.first").length;m++){
                    $(".ui-content>ul.con>li.first")[m].after(ul);
                }*/

                $(".ui-content>ul.con").click(function () {
                    $(this).find('.only').toggle();
                })
            }
        });


    };
}